package club.banyuan.controller;

import club.banyuan.bean.Blog;
import club.banyuan.service.BlogService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class IndexController {
    private BlogService blogService;

    @Autowired
    public IndexController(BlogService blogService) {
        this.blogService = blogService;
    }

    @GetMapping({"/","/index"})
    public String getHomePage(Model model,
                              @RequestParam(name = "page", defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Blog> blogs = blogService.getBlogs(pageNum,pageSize);
        model.addAttribute("blogs",blogs);
        //查db, 将blogs分页, 保存在model里面
        return "index";
    }




}
